<html>

<head>
    <style>
        .red {
            background-color: red;
        }

        .green {
            background-color: green;
        }
    </style>
</head>

<body>
    <div id="one" class="red">
        内容
    </div>
    <script>
        var one = document.getElementById("one");
        one.onmouseover = function () {
            one.setAttribute("class", "green");

        }

        one.onmouseout = function () {
            one.setAttribute("class", "red");
        }

    </script>
</body>

</html>